<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use think\facade\Request;
use think\helper\Str;
$method = Request::param('method');
header('Content-type: application/json');
if(!$method){
    exit(json_encode(['code'=>0,'msg'=>'method参数必传'],256));
}
if(substr_count($method,'/')!=3){
    exit(json_encode(['code'=>0,'msg'=>'method参数有误'],256));
}
$url = parse_url($method);

if(empty($url['scheme'])){
    exit(json_encode(['code'=>0,'msg'=>'method参数有误'],256));
}
$addon = strtolower($url['scheme']);
$controller = $url['host'];
$action = trim($url['path'], '/');
$controller = Str::snake((string)$controller);
$execute = '\\think\\addons\\Route::execute';
Route::rule('/', $execute)->completeMatch(true)
->append([
    'addon' => $addon,
    'controller' => $controller,
    'action' => $action
]);